package com.aclass.wang.c206;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;

public class Main5Activity extends AppCompatActivity implements BDLocationListener {
    LocationClient mLocationClient;
    TextView mText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main5);
        mText = (TextView) findViewById(R.id.text);
        mLocationClient =
                new LocationClient(getApplicationContext());
        mLocationClient.registerLocationListener(this);
        initLocation();
        mLocationClient.start();
    }

    private void initLocation() {
        LocationClientOption option = new LocationClientOption();
        option.setLocationMode(
                LocationClientOption.
                        LocationMode.Hight_Accuracy);
        option.setCoorType("bd0911");
        int span = 1000;
        option.setScanSpan(span);
        option.setIsNeedAddress(true);
        option.setOpenGps(true);
        mLocationClient.setLocOption(option);
    }

    @Override
    public void onReceiveLocation(BDLocation location) {
        StringBuilder sb = new StringBuilder(256);
        sb.append("经度：" + location.getLatitude() + "\n");
        sb.append("纬度：" + location.getLongitude() + "\n");
        mText.setText(sb.toString());
    }
}
